package com.ylb.rent.controller;

import com.ylb.rent.entity.Role;
import com.ylb.rent.entity.vo.RoleVo;
import com.ylb.rent.service.IPermissionService;
import com.ylb.rent.service.IRoleService;
import com.ylb.rent.util.MinioUtil;
import com.ylb.rent.util.R;
import io.minio.errors.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.List;

/**
 * @AUTHOR:游李滨
 * @DATE:2023/6/28 21:49
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Autowired
    IRoleService roleService;


    @GetMapping("/all")
    public String getAllRole(){
        List<Role> roleVos = roleService.getAllRole();
        return R.successJSONData("成功",roleVos);
    }

    @Autowired
    MinioUtil minioUtil;
    @PostMapping("/upload")
    public String up(@RequestBody MultipartFile file){
        String url="";
        try {
            url = minioUtil.put(file);
            System.out.println(url);
        } catch (IOException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (InsufficientDataException e) {
            e.printStackTrace();
        } catch (InternalException e) {
            e.printStackTrace();
        } catch (InvalidResponseException e) {
            e.printStackTrace();
        } catch (InvalidKeyException e) {
            e.printStackTrace();
        } catch (InvalidBucketNameException e) {
            e.printStackTrace();
        } catch (XmlParserException e) {
            e.printStackTrace();
        } catch (ErrorResponseException e) {
            e.printStackTrace();
        }
        return R.successJSONData(url);
    }
}
